<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class  MY_Controller  extends  CI_Controller {

    function __construct()
    {
        parent::__construct();
    }
    
    function _checktoken()
    {
        $use_token = $this->config->item('use_token');
        if($use_token) {
            $token_get = $this->input->post('token');
            $token_key = $this->config->item('token_key');
            if($token_get != $token_key) {
                $result['result'] = 'false';
                $result['msg'] = 'wrong token';
                $this->_outputjson($result);
            }
        }
    }

    function _outputjson($data)
    {
        $data = json_encode($data);
        $length = strlen($data);
        header('Content-Type: application/json; charset=utf-8');
        header('Content-Length: ' . $length);
        header('Access-Control-Allow-Origin: *');
        echo $data;
        exit();
    }

    function _outputjsonpost($data)
    {
        $data = json_encode($data);
        $length = strlen($data);
        header('Content-Type: application/json; charset=utf-8');
        header('Content-Length: ' . $length);
        echo $data;
        exit();
    }

    function _outputcurl($data)
    {
        $length = strlen($data);
        header('Content-Type: application/json');
        header('Content-Length: ' . $length);
        echo $data;
        exit();
    }
}